<?php
namespace Admin\Controller;
use Common\Controller\AdminCommonController;
use Think\Controller;
class IndexController extends AdminCommonController {
    public function index(){
        $this->display();
    }

    /**
     * 平台基本统计
     */
    public function basic(){
        $map = array();
        if($_SESSION['administrator']){
            $this->assign('identity','系统管理员');
            $map['id'] = array('gt',0);
            $orderTotal = M('order')->count('id');
            $finishOrderTotal = M('order')->where('status=5')->count('id');
        } else {
            $role = M()->table(C('DB_PREFIX').'auth_group_access a')->join(C('DB_PREFIX').'auth_group g on a.group_id=g.id')->where(array('a.uid'=>$this->manage_id))->cache(5)->getField('title');
            $this->assign('identity',$role);
            $map['uid'] = $this->manage_id;
            $shopList = D('Common/Shop')->getShopList($this->manage_id);
            $shopIdArr = array();
            foreach($shopList as $val){
                array_push($shopIdArr,$val['id']);
            }
            $where = array();
            $where['shop_id'] = array('in',$shopIdArr);
            $orderTotal = M('order')->where($where)->count('id');
            $where['status'] = 5;
            $finishOrderTotal = M('order')->where($where)->count('id');
        }
        $shopTotal = M('shop')->where($map)->count('id');
        $this->assign('shopTotal',$shopTotal);
        $this->assign('orderTotal',$orderTotal);
        $this->assign('finishOrderTotal',$finishOrderTotal);
        $this->display('basic');
    }
}